import * as SystemJs from './system.js'
/**
 * 全局基础颜色
 */
const baseColor = {
	// mainTitleColor: "#ba251e",
	mainTitleColor: "#506dff"
}

/**
 * 在u-charts.js的drawToolTip(textList, offset, opts, config, co）
 * 方法中修改textlist的数据格式
 * 自定义的textlist格式需要先在，config-ucharts.js中的formatter{}里面定义一个函数
 * 然后通过组件tooltipFormat="tooltipDemo1"属性来引用自定义的函数
 */
const defultUCharts = {

	/**
	 * 修改提示框的格式，通过'\n'回车符来区分进行换行处理
	 * @param {Object} textList
	 */
	changeToolTipTextList: function(textList, opts) {
		//自定义弹窗格式函数
		let newTextList = [];
		let codeList = [];
		if (textList && textList.length > 0) {
			textList.forEach((item, index) => {
				if (item.text.indexOf("\n") > -1) {
					var split = item.text.split("\n");
					if (split && split.length > 0) {
						for (var i = 0; i < split.length; i++) {
							var ir = i + 2;
							var obj = {};
							var code = split[i].replace("：", ":").split(":")[0]
							if (i === 0) {
								if (opts.categories && opts.categories.indexOf(code) < 0) {
									obj.color = item.color;
								} else {
									obj.color = null
								}
							} else {
								if (opts.series[index].name == code) {
									obj.color = item.color;
								} else {
									obj.color = opts.color[ir];
								}
							}
							obj.text = split[i];

							if (codeList && codeList.length > 0) {
								if (this.checkListInfo(codeList, code)) {
									continue;
								} else {
									codeList.push(code)
								}
							} else {
								codeList.push(code)
							}
							// console.log(code)
							newTextList.push(obj);
						}
					}
				}
			})
		}
		return newTextList;
	},
	/**
	 * 判断list是否为由重复元素
	 * @param {Object} codeList
	 * @param {Object} code
	 */
	checkListInfo: function(codeList, code) {
		var flag = false;
		if (codeList && codeList.length > 0) {
			for (var k = 0; k < codeList.length; k++) {
				var temCode = codeList[k]
				if (temCode == code) {
					return true
				} else {
					flag = false
				}
			}
		}
		return flag;
	},
	/**
	 * 绩效总金额自定义弹窗格式
	 * @param {Object} item
	 * @param {Object} category
	 * @param {Object} index
	 * @param {Object} opts
	 */
	formatTooltipTotalWage: function(item, category, index, opts) {
		var series = opts.chartData.legendData.points[0]
		console.log("opts", JSON.stringify(series))
		let temIndex = index;
		if (series.length > 0) {
			var text = "";
			var hgData = series[0].hgp;
			var bhgpData = series[0].bhgp
			text += category + "\n";
			text += item.name + "：" + item.data + "元" + "\n"
			text += hgData.name + "：" + hgData.data[temIndex] + "元" + "\n"
			text += bhgpData.name + "：" + bhgpData.data[temIndex] + "元"
			return text;
		}
	},
	/**
	 * 工序生产统计总产量自定义弹窗格式
	 * @param {Object} item
	 * @param {Object} category
	 * @param {Object} index
	 * @param {Object} opts
	 */
	formatTooltipTotalCount: function(item, category, index, opts) {
		var text = "";
		text += category + "\n";
		text += item.name + "：" + item.data + "个";
		return text;
	},
	/**
	 * 数据统计中日派工工序统计自定义弹窗格式
	 * @param {Object} val
	 * @param {Object} index
	 * @param {Object} series
	 * @param {Object} opts
	 */
	formatTooltipTotalPGGX: function(val, index, series, opts) {
		var text = "";
		text += val.name + "(派):" + val.number + '\n';
		text += "合格数:" + val.yNum + '\n';
		text += "不合格数:" + val.nNum;
		return text;
	},
	xAxisXYinCangDemo: function(val, index, opts) {
		let maxLenght = 4;
		let newstr = '';
		if (val.length > maxLenght) {
			return val.substring(0, maxLenght) + '...';
		} else {
			return  val;
		}
	}
}

/**
 * 全局配置文件中基础数据
 */
const configData = {
	/**
	 *底部导航栏显示列表
	 */
	tabList: [
		{
			pagePath: "/pages/main/mainPage",
			// "iconPath": "static/c3.png",
			// "selectedIconPath": "static/c4.png",
			iconfont: {
				icon: "layui-icon-component",
				selectedColor: "#3851f6",
				color: "#939393",
				size: "24px"
			},
			text: "工作台",
			fontSize: "10",
			customPrefix: 'iconfont'
		},
		{
			pagePath: "/pages/main/userInfo",
			// "iconPath": "static/c1.png",
			// "selectedIconPath": "static/c2.png",
			iconfont: {
				icon: "layui-icon layui-icon-username",
				selectedColor: "#3851f6",
				color: "#939393",
				size: "24px"
			},
			text: "我的",
			fontSize: "10",
			customPrefix: 'iconfont'
		}
	]
}

const getBaseInfo = {
	/**
	 *获取登录用户信息
	 */
	getUserInfo: function() {
		var obj = {};
		obj = uni.getStorageSync('userInfo')
		return obj;
	},
	/**
	 * 获取单据临时编码
	 * @param {Object} obj2
	 */
	addTempCode: async function(obj2) {
		var obj = "";
		var acount = uni.getStorageSync('account');
		var obj1 = {};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetScanCode',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = "";
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = "";
		})
		return obj;
	},
	/**
	 * 获取账套信息
	 * @param {Object} obj2
	 */
	getAcountInfo: async function(obj2) {
		var obj = [];
		var obj1 = {
			mobType: 'H5'
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/get_Acount',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
				console.log("1111111111"+obj)
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取临时编码列表信息
	 * @param {Object} obj2
	 */
	getTempCode: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetTempCode',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取仓库信息
	 * @param {Object} obj2
	 */
	getWareHouse: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetWareHouse',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取仓库默认显示信息
	 * @param {Object} obj2
	 */
	getDefaultWareHouse: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetInOutWareStyle',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取部门信息
	 * @param {Object} obj2
	 */
	getDepartment: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetDepartment',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取部门默认信息
	 * @param {Object} obj2
	 */
	getDefaultDepartment: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetInOutDeptStyle',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取出入库收发类型默认信息
	 * @param {Object} obj2
	 */
	getDefaultRdStyle: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetInOutRdStyle',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取生产子工序信息
	 * @param {Object} obj2
	 */
	getGXInfo: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetGXInfo',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取生产工序班组信息
	 * @param {Object} obj2
	 */
	getGXGroupInfo: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetGXGroupInfo',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取系统字典表字段信息
	 * @param {Object} obj2
	 * @param {String} obj2.code - 参数编码
	 * @param {String} obj2.name - 参数名称
	 * @param {String} obj2.types - 参数类型
	 * @param {String} obj2.extendFile - 参数大类   
	 */
	getDictionaryInfo: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetDictionaryInfo',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	/**
	 * 获取系统参数表字段信息
	 * @param {Object} obj2
	 * @param {String} obj2.code - 参数编码
	 * @param {String} obj2.name - 参数名称 
	 */
	getParamentersInfo: async function(obj2) {
		var obj = [];
		var acount = uni.getStorageSync('account');
		var obj1 = {
			mobType: 'H5',
			baseCode: acount
		};
		var data = Object.assign(obj1, obj2)
		await SystemJs.httpUnit.requestCryptoPost({
			url: 'App/GetParamentersInfo',
			data: data
		}).then((res) => {
			if (res.Result) {
				obj = res.Data;
			} else {
				SystemJs.httpUnit.uniToast(res.Message)
				obj = [];
			}
		}).catch((err) => {
			SystemJs.httpUnit.uniToast(JSON.stringify(err))
			obj = [];
		})
		return obj;
	},
	
}

export {
	baseColor,
	configData,
	getBaseInfo,
	defultUCharts
}